<template>
  <el-dialog
    v-if="open"
    :title="title"
    v-model="open"
    :close-on-click-modal="false"
    draggable
    width="70%"
    append-to-body
    :before-close="cancel"
  >
    <div class="dialog-container">
      <el-table
        v-loading="loading"
        border
        :data="typeList"
      >
      <!-- @selection-change="handleSelectionChange" -->
        <!-- <el-table-column type="selection" width="55" /> -->
        <el-table-column label="工单编号" prop="orderCode" />
        <el-table-column label="产线" prop="lineName" />
        <el-table-column label="工艺段" prop="sectionName" />
        <!-- <el-table-column label="产品编号" prop="prodCode" /> -->
        <!-- <el-table-column label="产品名称" prop="prodName" /> -->
        <el-table-column label="计划产量" prop="planNumber" />
        <el-table-column label="单位" prop="unit" />
        <el-table-column label="计划开始时间" prop="planStartTime">
          <template #default="scope">
            <span>{{ scope.row.planStartTime }}</span>
          </template>
        </el-table-column>
        <el-table-column label="计划结束时间" prop="planEndTime">
          <template #default="scope">
            <span>{{ scope.row.planEndTime }}</span>
          </template>
        </el-table-column>
        <!-- <el-table-column label="工厂" prop="factory" />
        <el-table-column label="工段" prop="workSection" /> -->
        <el-table-column label="状态" prop="status"
        ><template #default="scope">
          <dict-tag :options="work_order_status" :value="scope.row.status" />
        </template>
      </el-table-column>
      </el-table>

      <pagination
        v-show="total > 0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="cancel">关 闭</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup name="UserSelect">
import { toRefs } from "vue";

import { listWorkOrder } from "@/api/base/workOrder/workOrder";

const { proxy } = getCurrentInstance();
const props = defineProps([
  "placeholder",
  "title",
  "multiple",
  "openDisOrder",
  "orderList",
]);
const { title, multiple, openDisOrder, orderList } = toRefs(props);
const { work_order_status } = proxy.useDict("work_order_status");
const emit = defineEmits(["change"]);
const open = ref(false);
const loading = ref(true);

const total = ref(0);
const typeList = ref([]);

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    // status: "progressing",
    status: "",
  },
});

const { queryParams } = toRefs(data);

watch(openDisOrder, (val) => {
  open.value = val;
  getList();
});

function getList() {
  loading.value = true;
  queryParams.value.orderCode = orderList.value[0].orderCode;
  let newForm = JSON.parse(JSON.stringify(queryParams.value));
  listWorkOrder(proxy.addDateRange(newForm)).then((response) => {
    typeList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

function cancel() {
  emit("changeDisOrderList", []);
}
</script>
